package com.ln.store.web.base;

import java.io.IOException;
import java.lang.reflect.Method;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class BaseServlet
 */
public class BaseServlet extends HttpServlet {
	
	@Override
	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//获取客户端提交到服务器method对应的值
				String md = request.getParameter("method");
				if (md == null || "".equals(md)||md.trim().equals("")) {
					md="execute";
				}
				//定义变量，存放功能执行完毕之后要转发的路径
				String path = null;
				//获取到当前字节码对象
				Class clazz = this.getClass();
				try {
					Method method = clazz.getMethod(md, HttpServletRequest.class,HttpServletResponse.class);
					if (method != null) {
						path = (String)method.invoke(this, request,response);
					}
					if (path != null) {
						//服务器转发
						request.getRequestDispatcher(path).forward(request, response);;
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	}

}
